package com.zhukaiyuan.oauth2.cms.controller;


import com.zhukaiyuan.oauth2.cms.entity.Content;
import com.zhukaiyuan.oauth2.cms.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhukaiyuan
 * @since 2020-06-20
 */
@RestController
@RequestMapping("/cms/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    @PostMapping
    public String saveOrUpdate(Content content){
        boolean b = contentService.saveOrUpdate(content);
        return b ? "SUCCESS": "FAILURE";
    }

    @DeleteMapping("/{id}")
    public String delById(@PathVariable Long id){
        boolean b = contentService.removeById(id);
        return  b ? "SUCCESS": "FAILURE";
    }



    @GetMapping("/{id}")
    public Content getById(@PathVariable Long id){
        Content content = contentService.getById(id);
        return content;
    }

    @GetMapping
    public List<Content> getAll(){
        List<Content> list = contentService.list();
        return list;
    }
}
